package cn.edu.scau.cmi.xuxingao.composite.consistent;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ConsistentComposite extends ConsistentComponent{
		
		private String name;
		private List<ConsistentComponent> children = new ArrayList<ConsistentComponent>();
		
		@Override
		public String intro(int i) {
			Iterator<ConsistentComponent> iter = children.iterator();
			String info="";
			for(int j=0;j<i;j++) {
				info+="       ";
			}
			info=info+"团队："+name;
			while(iter.hasNext()) {
				ConsistentComponent child = iter.next();
				info = info+'\n'+child.intro(i+1);
			}
			//info+="\n";
			return info;
		};
		
		public ConsistentComposite() {
			
		}
		public ConsistentComposite(String name) {
			this.name=name;
		}
		
		public void add(ConsistentComponent child) {
			if(child!=null)
				children.add(child);
		}
		
		public void remove(ConsistentComponent child) {
			if(children.contains(child)) {
				children.remove(child);
			}else {
				System.out.println("团队中无此成员！");
			}
		}
		
		public List<ConsistentComponent> getChildren(){
			return children;
		}
		public void setName(String name) {
			this.name = name;
		}
		
		public String getName() {
			return name;
		}
		
}
